package com.yuexun.dhdoctor.module.departmentDocumentNew.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.departmentDocumentNew.bean.ShareDocBean;
import com.yuexun.dhdoctor.util.FileUtils;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by Administrator on 2018/11/29 0029.
 */

public class FileAdapter extends KJAdapter<ShareDocBean> {
    private Context context;

    public FileAdapter(AbsListView view, Collection<ShareDocBean> mDatas, int itemLayoutId,Context mContext) {
        super(view, mDatas, itemLayoutId);
        this.context = mContext;
    }

    @Override
    public void convert(AdapterHolder helper, final ShareDocBean item, boolean isScrolling, final int position) {
        TextView title = helper.getView(R.id.tv_doc_department_title);
        TextView time = helper.getView(R.id.tv_doc_department_date);
        helper.setText(R.id.tv_upload_name, "上传人:"+item.getAccountName());
        CheckBox selectView = helper.getView(R.id.checkbox_doc_department);
        title.setText(item.getDocName() + "(" + item.getFileSize() + ")");
        time.setText(item.getCreateTime());

        selectView.setVisibility(View.VISIBLE);
        selectView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isSelect()) {
                    item.setSelect(false);
                } else {
                    item.setSelect(true);
                }
                notifyDataSetChanged();
            }
        });

        selectView.setChecked(item.isSelect());
        final FileUtils fileUtils = new FileUtils(context);
        final String[] filenames = item.getDocName().split("\\.");
        if (fileUtils.isFileExist(AppConfig.FILE_CONTENT + item.getFileUUId() + "." + filenames[filenames.length - 1])) {
            helper.setText(R.id.tv_download_status, "状态:已下载");
        } else {
            helper.setText(R.id.tv_download_status, "状态:未下载");
        }
    }
}
